﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dawn_of_Man
{
    [Serializable()]
    public class Building
    {
        public String name { get; set; }
        public int baseGoodPrTurn { get; set; }
        public int size { get; set; }
        public int construction { get; set; }
        public int constructionWood { get; set; }
        public int constructionBlocks { get; set; }
        public int constructionTools { get; set; }
        public Ressource res { get; set; }

        [field: NonSerialized]
        public event EventHandler Changed;

        private List<Homosapien> working = new List<Homosapien>();

        // Invoke the Changed event; called whenever list changes:
        [field: NonSerialized]
        protected virtual void OnChanged(EventArgs e)
        {
            if (Changed != null)
                Changed(this, e);
        }

        public override string ToString()
        {
            return name;
        }

        public int getTotalCapacity()
        {
            return size * 2;
        }

        public int getAvailiableCapacity()
        {
            return (size * 2) - working.Count;
        }

        public List<Homosapien> getWorkers()
        {
            return working;
        }

        public bool addWorker(Homosapien worker)
        {
            if (working.Count + 1 <= getTotalCapacity())
            {
                working.Add(worker);
                OnChanged(EventArgs.Empty);
                return true;
            }
            else
                return false;
        }

        public void removeWorker(Homosapien worker)
        {
            working.Remove(worker);
            OnChanged(EventArgs.Empty);
        }

        public int getTotalGoodsPrTurn()
        {
            int goods = 0;

            if (working.Count != 0 && baseGoodPrTurn > 0)
            {
                    goods = working.Count* baseGoodPrTurn;
            }

            return goods;
        }

        public int getConstructionBlocksPrTurn()
        {
            
            return constructionBlocks * size;
        }

        public int getConstructionWoodPrTurn()
        {
            return constructionWood * size;
        }

        public int getConstructionToolsPrTurn()
        {
            return constructionTools * size;
        }

        public int getTurnsLeft(int constructors)
        {
            return construction / (constructors * 5);
        }
    }
}
